package com.wanxi.step07test.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SUser implements UserDetails, Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;
    private String username;
    private String password;
    private String icon;
    private String email;
    private String nickName;
    private String note;
    private Date createTime;
    private Date loginTime;
    private Integer enable;


    private Integer page;
    private Integer limit;

    private String role;
    private String phone;
    private List<Role> roleList;

    private Set<? extends GrantedAuthority> authorities;

    @JsonIgnore
    @Override //权限集合
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }


    @Override // 密码
    public String getPassword() {
        return this.password;
    }


    @Override // 用户名
    public String getUsername() {
        return this.username;
    }

    @JsonIgnore
    @Override // 账号是否过期
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override // 账号有没有被锁定
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override // 证书是否过期
    public boolean isCredentialsNonExpired() {
        return true;
    }


    @JsonIgnore
    @Override
    public boolean isEnabled() {
        if(this.enable == null){
            return false;
        }
        return this.enable == 1;
    }
}
